﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;
using Styx.CommonBot;
using Styx;

namespace XS
{
    class XS_Hunter_Survival
    {
        /* this one really is important for the sake of mankind */
        private static LocalPlayer Me { get { return XSCommon.Me; } }


        public static Composite Player(CanRunDecoratorDelegate cond)
        {
            return Boss(cond);
        }   //add pvp logic, currently only Boss(), 30-11-2012

        public static Composite Boss(CanRunDecoratorDelegate cond)
        {
            return (
                new Decorator(
                    delegate(object a)
                    {
                        if (!cond(a))
                            return false;
                        if (Me.Specialization != WoWSpec.HunterSurvival)
                            return false;
                        
                        XSCommon.writeDebug("SV, Boss");
                        return true;
                    },
                    new PrioritySelector(
                        /* Lets fire some cooldowns first, shall we? i'd like to implement a "on trinket procc / bloodlust use the force, luke" logic */
                        //Racial, if we're ork or troll we'll use our hulk-powers
                        XSCommon.UseCooldown_Racial(),

                        //Trinket 1 and 2, we've set if we'd like to use them in our XS_Class.cs - or in our not yet available gui, HÜA
                        XSCommon.UseCooldown_Trinket(1, XS_Hunter.varTrinket1),
                        XSCommon.UseCooldown_Trinket(2, XS_Hunter.varTrinket2),

                        //Lifeblood cause we can
                        XSCommon.UseCooldown_Herbalism(),

                        //Rapid Fire
                        //XSCommon.CastSpell("Rapid Fire", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) > 5),
                        XSCommon.UseCooldown_Hunter_RapidFire(),

                        //Stampede
                        XSCommon.CastSpell("Stampede", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) > 5),

                        //Explosive Shot on cooldown. Cast multiple with Lock and Load, but only if our target isn't already suffering from our mighty explolosions
                        XSCommon.CastSpell("Explosive Shot", ret => XSCommon.MyAuraTimeMilliseconds("Explosive Shot", Me.CurrentTarget) < 500),
                    
                        //Thrill of the Hunt Procs
                        //XSCommon.CastSpell("Arcane Shot", ret => XSCommon.AuraTime("Thrill of the Hunt", Me) >= 1),
                        XSCommon.CastSpell("Arcane Shot", ret => XSCommon.IsMyAuraActive("Thrill of the Hunt")),

                        //Kill Shot when target is below 20% Health, obligatory
                        XSCommon.CastSpell("Kill Shot", ret => Me.CurrentTarget.HealthPercent < 20),

                        //Black Arrow on cooldown. Surprise.
                        XSCommon.CastSpell("Black Arrow", ret => XSCommon.MyAuraTime("Black Arrow", Me.CurrentTarget) < 2),

                        //Poison the fucker
                        XSCommon.CastSpell("Serpent Sting", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5 && XSCommon.MyAuraTime("Serpent Sting", Me.CurrentTarget) < 1),

                        //Tier 4
                        XSCommon.CastSpell("Fervor", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3 && Me.CurrentFocus <= 60),
                        XSCommon.CastSpell("Dire Beast", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3 && Me.CurrentFocus <= 60),

                        //Tier 5
                        XSCommon.CastSpell("A Murder of Crows", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 10),
                        XSCommon.CastSpell("Blink Strike", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 2),
                        XSCommon.CastSpell("Lynx Rush", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5),

                        //Tier 6
                        XSCommon.CastSpell("Glaive Toss", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 2),
                        XSCommon.CastSpell("Powershot", ret => !Me.HasAura(56453) && XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5),
                        XSCommon.CastSpell("Barrage", ret => !Me.HasAura(56453) && XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3),

                        //Important things are done, dump focus with arcane shot, build focis with cobra ...
                        XSCommon.CastSpell("Steady Shot", ret => Me.CurrentFocus <= 70 && !XSCommon.IsMyAuraActive("Thrill of the Hunt")),
                        //XSCommon.CastSpell("Arcane Shot", ret => XSCommon.AuraTime("Thrill of the Hunt", Me) >= 1 || (Me.CurrentFocus >= 50 && !XSCommon.CanCast("A Murder of Crows")) || Me.CurrentFocus > 90)
                        XSCommon.CastSpell("Arcane Shot", ret => XSCommon.IsMyAuraActive("Thrill of the Hunt") || (Me.CurrentFocus >= 50 && !XSCommon.CanCast("A Murder of Crows")) || Me.CurrentFocus > 70)
                    )
                )
            );
        }   //done, 30-11-2012; updated, 01-12-2012

        public static Composite AoE(CanRunDecoratorDelegate cond)
        {
            return (
                new Decorator(
                    delegate(object a)
                    {
                        if (!cond(a))
                            return false;
                        if (Me.Specialization != WoWSpec.HunterSurvival)
                            return false;

                        XSCommon.writeDebug("SV, AoE");
                        return true;
                    },
                    new PrioritySelector(
                        /* Lets fire some cooldowns first, shall we? i'd like to implement a "on trinket procc / bloodlust use the force, luke" logic */
                        //Racial, if we're ork or troll we'll use our hulk-powers
                        XSCommon.UseCooldown_Racial(),

                        //Trinket 1 and 2, we've set if we'd like to use them in our XS_Class.cs - or in our not yet available gui, HÜA
                        XSCommon.UseCooldown_Trinket(1, XS_Hunter.varTrinket1),
                        XSCommon.UseCooldown_Trinket(2, XS_Hunter.varTrinket2),

                        //Lifeblood cause we can
                        XSCommon.UseCooldown_Herbalism(),

                        //Multi-shot is THE priority.
                        //XSCommon.CastSpell("Multi-Shot", ret => (Me.CurrentFocus > 20 && XSCommon.AuraTime("Thrill of the Hunt", Me) > 1) || Me.CurrentFocus >= 40),
                        XSCommon.CastSpell("Multi-Shot", ret => (Me.CurrentFocus >= 20 && XSCommon.IsMyAuraActive("Thrill of the Hunt")) || Me.CurrentFocus >= 40),

                        //Tier 4 if focus low, gainer
                        XSCommon.CastSpell("Fervor", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3 && Me.CurrentFocus <= 60),
                        XSCommon.CastSpell("Dire Beast", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3 && Me.CurrentFocus <= 60),

                        //Tier 5 only if much focus.
                        XSCommon.CastSpell("Blink Strike", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 2 && Me.CurrentFocus >= 60),
                        XSCommon.CastSpell("Lynx Rush", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5 && Me.CurrentFocus >= 60),

                        //Tier-6-Ability on cooldown
                        XSCommon.CastSpell("Glaive Toss", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 1),
                        XSCommon.CastSpell("Powershot", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5 && XSCommon.AddCluster()),
                        XSCommon.CastSpell("Barrage", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3),

                        //Explosive Shot only with procc!
                        //XSCommon.CastSpell("Explosive Shot", ret => XSCommon.AuraTime("Lock and Load", Me) > 1 && XSCommon.MyAuraTimeMilliseconds("Explosive Shot", Me.CurrentTarget) < 500),
                        XSCommon.CastSpell("Explosive Shot", ret => XSCommon.IsMyAuraActive("Lock and Load") && XSCommon.MyAuraTimeMilliseconds("Explosive Shot", Me.CurrentTarget) < 500),
                    
                        //Ice Trap cause I glyphed the shit!
                        new Decorator(ret => SpellManager.Spells["Ice Trap"].CooldownTimeLeft.TotalSeconds < 1 && Me.CurrentTarget.InLineOfSight,
                            new PrioritySelector(
                                XSCommon.CastSelfSpell("Trap Launcher", ret => !Me.HasAura("Trap Launcher")),
                                XSCommon.CastOnUnitLocation("Ice Trap", Me.CurrentTarget, ret => Me.HasAura("Trap Launcher"))
                            )
                        ),

                        //Explosive Trap for AoE
                        new Decorator(ret => !Me.CurrentTarget.IsMoving && SpellManager.Spells["Explosive Trap"].CooldownTimeLeft.TotalSeconds < 1 && Me.CurrentTarget.InLineOfSight,
                            new PrioritySelector(
                                XSCommon.CastSelfSpell("Trap Launcher", ret => !Me.HasAura("Trap Launcher")),
                                XSCommon.CastOnUnitLocation("Explosive Trap", Me.CurrentTarget, ret => Me.HasAura("Trap Launcher"))
                            )
                        ),

                        //this must be the filler then
                        XSCommon.CastSpell("Steady Shot", ret => !XSCommon.IsMyAuraActive("Lock and Load") && Me.CurrentFocus < 40),

                        //i wonder if we ever reach this.
                        XSCommon.CastSpell("Kill Shot", ret => Me.CurrentTarget.HealthPercent < 20)
                    )
                )
            );
        }   //done, 30-11-2012; updated, 01-12-2012

        public static Composite Normal(CanRunDecoratorDelegate cond)
        {
            return (
                new Decorator(
                    delegate(object a)
                    {
                        if (!cond(a))
                            return false;
                        if (Me.Specialization != WoWSpec.HunterSurvival)
                            return false;

                        XSCommon.writeDebug("SV, Normal");
                        return true;
                    },
                    new PrioritySelector(
                        /* Normal Rotation, will do simple stuff. Some cooldowns :eeeek: but no "big" ones */
                        //Racial, if we're ork or troll we'll use our hulk-powers
                        XSCommon.UseCooldown_Racial(),

                        //Trinket 1 and 2, we've set if we'd like to use them in our XS_Class.cs - or in our not yet available gui, HÜA
                        XSCommon.UseCooldown_Trinket(1, XS_Hunter.varTrinket1),
                        XSCommon.UseCooldown_Trinket(2, XS_Hunter.varTrinket2),

                        //Lifeblood cause we can
                        XSCommon.UseCooldown_Herbalism(),

                        //Explosive Shot on cooldown. Cast multiple with Lock and Load, but only if our target isn't already suffering from our mighty explolosions
                        XSCommon.CastSpell("Explosive Shot", ret => XSCommon.MyAuraTimeMilliseconds("Explosive Shot", Me.CurrentTarget) < 500),

                        //Thrill of the Hunt Procs
                        //XSCommon.CastSpell("Arcane Shot", ret => XSCommon.AuraTime("Thrill of the Hunt", Me) >= 1),
                        XSCommon.CastSpell("Arcane Shot", ret => XSCommon.IsMyAuraActive("Thrill of the Hunt")),

                        //Kill Shot when target is below 20% Health, obligatory
                        XSCommon.CastSpell("Kill Shot", ret => Me.CurrentTarget.HealthPercent < 20),

                        //Black Arrow on cooldown. Surprise.
                        XSCommon.CastSpell("Black Arrow", ret => XSCommon.MyAuraTime("Black Arrow", Me.CurrentTarget) < 2),

                        //Poison the fucker
                        XSCommon.CastSpell("Serpent Sting", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5 && XSCommon.MyAuraTime("Serpent Sting", Me.CurrentTarget) < 1),

                        //Tier 4
                        XSCommon.CastSpell("Fervor", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3 && Me.CurrentFocus <= 60),
                        XSCommon.CastSpell("Dire Beast", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3 && Me.CurrentFocus <= 60),

                        //Tier 5
                        XSCommon.CastSpell("Blink Strike", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 2),
                        XSCommon.CastSpell("Lynx Rush", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5),

                        //Tier 6
                        XSCommon.CastSpell("Glaive Toss", ret => XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 2),
                        XSCommon.CastSpell("Powershot", ret => !Me.HasAura(56453) && XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 5),
                        XSCommon.CastSpell("Barrage", ret => !Me.HasAura(56453) && XSCommon.CalculateTimeToDeath(Me.CurrentTarget) >= 3),

                        //Important things are done, dump focus with arcane shot, build focis with cobra ...
                        XSCommon.CastSpell("Steady Shot", ret => Me.CurrentFocus < 70 && !XSCommon.IsMyAuraActive("Thrill of the Hunt")),
                        //XSCommon.CastSpell("Arcane Shot", ret => XSCommon.AuraTime("Thrill of the Hunt", Me) >= 1 || (Me.CurrentFocus >= 50 && !XSCommon.CanCast("A Murder of Crows")) || Me.CurrentFocus > 90)
                        XSCommon.CastSpell("Arcane Shot", ret => XSCommon.IsMyAuraActive("Thrill of the Hunt") || (Me.CurrentFocus >= 50 && !XSCommon.CanCast("A Murder of Crows")) || Me.CurrentFocus > 70)
                    )
                )
            );
        }   //done, 30-11-2012; updated, 01-12-2012
    }
}






